home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 140
/
(Vol 140) Sep 19 2011.iso
/
Games
/
world-wars.swf
/
scripts
/
__Packages
/
classes
/
GameWW.as
< prev
next >
Wrap
Text File
|
2011-09-19
|
16KB
|
555 lines
class classes.GameWW
{
function GameWW(gmc, umc, etmc, wt, ul, fb)
{
this.GAME_MC = gmc;
this.UNITS_MC = umc;
this.WAITER = wt;
this.UNITS_LIST = ul;
this.END_TURN_MC = etmc;
this.FIGHTBOX = fb;
this.AUTOPLAYER = false;
this.MAP = new classes.Map(this.GAME_MC,this);
this.AI = new classes.GameAI(this);
this.counter = 0;
this.TRACER = _root.createEmptyMovieClip("tracer",1);
this.PLAYER_MOVE = 1;
}
function newGame(players, callBack)
{
if(this.WAITER.status == "ready_off")
{
var root = this;
this.PLAYERS_NO = players;
this.PLAYERS_CACHES = new Array();
var i = 0;
while(i < this.PLAYERS_NO)
{
this.PLAYERS_CACHES.push(0);
i++;
}
this.WAITER.show();
this.GAME_MC.onEnterFrame = function()
{
with(root)
{
if(WAITER.status == "ready_on")
{
MAP.createMap(PLAYERS_NO);
counter = MAP.TERRITORIES_ARR.length + 10;
arrangeUnits();
WAITER.hide();
var refArr = new Array();
var i = 1;
while(i <= PLAYERS_NO)
{
refArr.push(unitsToAdd(i));
i++;
}
UNITS_LIST.setList(MAP.TERRITORIES_ARR,refArr,PLAYERS_NO);
}
}
if(root.WAITER.status == "ready_off")
{
callBack();
delete this.onEnterFrame;
}
};
}
}
function init()
{
this.UNITS_LIST.selectPlayer(this.PLAYER_MOVE);
if(this.PLAYER_MOVE != 1 || this.AUTOPLAYER)
{
this.AI.cleverMove(this.PLAYER_MOVE);
}
else
{
this.END_TURN_MC.gotoAndPlay(2);
this.MAP.startInterface();
}
}
function nextPlayer()
{
this.PLAYER_MOVE = this.PLAYER_MOVE + 1;
if(this.PLAYER_MOVE > this.PLAYERS_NO)
{
this.PLAYER_MOVE = 1;
}
if(this.PLAYER_MOVE != 1 || this.AUTOPLAYER)
{
this.AI.cleverMove(this.PLAYER_MOVE);
}
else
{
this.END_TURN_MC.gotoAndPlay(2);
this.MAP.startInterface();
}
if(this.PLAYER_MOVE == 1)
{
this.FIGHTBOX.resetSkipMode();
}
this.UNITS_LIST.selectPlayer(this.PLAYER_MOVE);
}
function isGameFinished()
{
var _loc3_ = 0;
var _loc2_ = 0;
while(_loc2_ < this.MAP.TERRITORIES_ARR.length)
{
if(this.MAP.TERRITORIES_ARR[_loc2_].player == 1)
{
_loc3_ = _loc3_ + 1;
}
_loc2_ = _loc2_ + 1;
}
if(_loc3_ == this.MAP.TERRITORIES_ARR.length)
{
this.PLAYER_WIN();
return true;
}
if(_loc3_ == 0)
{
this.GAME_OVER();
return true;
}
return false;
}
function PLAYER_WIN()
{
_root.YOUWIN_MC._visible = true;
_root.YOUWIN_MC.gotoAndPlay(2);
}
function GAME_OVER()
{
_root.GAMEOVER_MC._visible = true;
_root.GAMEOVER_MC.gotoAndPlay(2);
}
function arrangeUnits()
{
var _loc9_ = [0,0,0,0,0,0,0,0];
var _loc8_ = new Array();
this.clearAll();
this.rubbish_arr = new Array();
var _loc3_ = 0;
while(_loc3_ < this.MAP.TERRITORIES_ARR.length)
{
var _loc4_ = this.MAP.TERRITORIES_ARR[_loc3_].arr;
var _loc7_ = 0;
var _loc6_ = 0;
var _loc2_ = 0;
while(_loc2_ < _loc4_.length)
{
_loc7_ += _loc4_[_loc2_]._x;
_loc6_ += _loc4_[_loc2_]._y;
_loc2_ = _loc2_ + 1;
}
_loc7_ /= _loc4_.length;
_loc6_ /= _loc4_.length;
this.counter = _loc3_;
var _loc5_ = this.UNITS_MC.attachMovie("UNIT","unit_" + this.counter,2 + this.counter * 2);
this.counter = this.counter + 1;
_loc5_._x = _loc7_;
_loc5_._y = _loc6_;
_loc5_.setUnit(this.MAP.TERRITORIES_ARR[_loc3_].army,this.MAP.TERRITORIES_ARR[_loc3_].unitsNO,this.MAP.TERRITORIES_ARR[_loc3_].player);
this.MAP.TERRITORIES_ARR[_loc3_].unitsMC = _loc5_;
_loc8_.push(_loc5_);
this.rubbish_arr.push(_loc5_);
_loc3_ = _loc3_ + 1;
}
this.unitsSmartDepths(_loc8_);
}
function unitsSmartDepths(unitsArr)
{
var _loc5_ = 0;
while(_loc5_ < unitsArr.length)
{
var _loc2_ = unitsArr.length - 1;
while(_loc2_ > _loc5_)
{
if(unitsArr[_loc2_ - 1]._y > unitsArr[_loc2_]._y)
{
var _loc4_ = unitsArr[_loc2_];
unitsArr[_loc2_] = unitsArr[_loc2_ - 1];
unitsArr[_loc2_ - 1] = _loc4_;
}
_loc2_ = _loc2_ - 1;
}
_loc5_ = _loc5_ + 1;
}
_loc5_ = 0;
while(_loc5_ < unitsArr.length)
{
unitsArr[_loc5_].swapDepths(2 + this.counter * 2);
this.counter = this.counter + 1;
_loc5_ = _loc5_ + 1;
}
}
function showBiggestArea()
{
var _loc7_ = new Array();
var _loc3_ = 0;
while(_loc3_ < this.MAP.TERRITORIES_ARR.length)
{
if(this.MAP.TERRITORIES_ARR[_loc3_].player == this.PLAYER_MOVE)
{
_loc7_.push(this.MAP.TERRITORIES_ARR[_loc3_]);
}
_loc3_ = _loc3_ + 1;
}
var _loc4_ = new Array();
_loc3_ = 0;
while(_loc3_ < _loc7_.length)
{
var _loc6_ = _loc7_[_loc3_];
if(this.isThere(_loc6_,_loc4_) == false)
{
var _loc5_ = new Array();
this.generate(_loc6_,_loc5_);
_loc4_.push(_loc5_);
}
_loc3_ = _loc3_ + 1;
}
this.maxArea = new Array();
_loc3_ = 0;
while(_loc3_ < _loc4_.length)
{
if(_loc4_[_loc3_].length > this.maxArea.length)
{
this.maxArea = _loc4_[_loc3_];
}
_loc3_ = _loc3_ + 1;
}
_loc3_ = 0;
while(_loc3_ < this.maxArea.length)
{
this.MAP.lightOnTerritory(this.maxArea[_loc3_]);
_loc3_ = _loc3_ + 1;
}
var _loc9_ = 0;
var _loc8_ = 0;
_loc3_ = 0;
while(_loc3_ < this.maxArea.length)
{
_loc9_ += this.maxArea[_loc3_].unitsMC._x;
_loc8_ += this.maxArea[_loc3_].unitsMC._y;
_loc3_ = _loc3_ + 1;
}
_loc9_ /= this.maxArea.length;
_loc8_ /= this.maxArea.length;
var _loc10_ = this.UNITS_MC.attachMovie("CLOUD","CLOUD",this.UNITS_MC.getNextHighestDepth());
_loc10_.toAdd = this.maxArea.length;
_loc10_._x = _loc9_;
_loc10_._y = _loc8_;
_global.setTimeout(mx.utils.Delegate.create(this,this.hideBiggestArea),1200);
}
function hideBiggestArea()
{
var _loc2_ = 0;
while(_loc2_ < this.maxArea.length)
{
this.MAP.lightOffTerritory(this.maxArea[_loc2_]);
_loc2_ = _loc2_ + 1;
}
}
function addUnits()
{
var _loc12_ = this.unitsToAdd(this.PLAYER_MOVE) + this.PLAYERS_CACHES[this.PLAYER_MOVE - 1];
var _loc5_ = new Array();
var _loc6_ = 0;
while(_loc6_ < this.MAP.TERRITORIES_ARR.length)
{
if(this.MAP.TERRITORIES_ARR[_loc6_].player == this.PLAYER_MOVE)
{
_loc5_.push(this.MAP.TERRITORIES_ARR[_loc6_]);
}
_loc6_ = _loc6_ + 1;
}
var _loc4_ = new Array();
_loc6_ = 0;
while(_loc6_ < _loc5_.length)
{
_loc4_.push(0);
_loc6_ = _loc6_ + 1;
}
var _loc11_ = _loc5_.length;
while(_loc12_ > 0 && _loc11_ > 0)
{
_loc11_ = _loc5_.length;
_loc6_ = 0;
while(_loc6_ < _loc4_.length)
{
if(_loc4_[_loc6_] + _loc5_[_loc6_].unitsNO >= 8)
{
_loc11_ = _loc11_ - 1;
}
_loc6_ = _loc6_ + 1;
}
var _loc7_ = this.random2(_loc5_.length - 1);
var _loc9_ = false;
_loc6_ = 0;
while(_loc6_ < _loc4_.length && !_loc9_)
{
if(_loc4_[(_loc7_ + _loc6_) % _loc4_.length] + _loc5_[(_loc7_ + _loc6_) % _loc4_.length].unitsNO < 8)
{
_loc4_[(_loc7_ + _loc6_) % _loc4_.length]++;
_loc12_ = _loc12_ - 1;
_loc9_ = true;
}
_loc6_ = _loc6_ + 1;
}
}
if(_loc12_ > 32)
{
_loc12_ = 32;
}
if(_loc12_ > 0 && this.PLAYER_MOVE == 1)
{
_root.EXTRA_UNITS.showExtra = _loc12_;
_root.EXTRA_UNITS.gotoAndPlay(2);
}
this.PLAYERS_CACHES[this.PLAYER_MOVE - 1] = _loc12_;
var _loc14_ = 0;
_loc6_ = 0;
while(_loc6_ < _loc5_.length)
{
if(_loc4_[_loc6_] > 0)
{
var _loc8_ = this.UNITS_MC.attachMovie("UNITS_ADDER","adder_to_" + _loc5_[_loc6_].unitsMC._name,_loc5_[_loc6_].unitsMC.getDepth() - 1);
_loc5_[_loc6_].unitsNO += _loc4_[_loc6_];
_loc8_._x = _loc5_[_loc6_].unitsMC._x + 10;
_loc8_._y = _loc5_[_loc6_].unitsMC._y;
_loc8_.unitsMC = _loc5_[_loc6_].unitsMC;
_loc8_.army = _loc5_[_loc6_].army;
_loc8_.newUnitsNO = _loc5_[_loc6_].unitsNO;
_loc8_.player = _loc5_[_loc6_].player;
}
_loc6_ = _loc6_ + 1;
}
_global.SOUNDS.playSound("przemarsz - do uzupełniania jednostek.wav");
var _loc13_ = false;
while(!_loc13_)
{
var _loc10_ = this.PLAYER_MOVE + 1;
if(_loc10_ > this.PLAYERS_NO)
{
_loc10_ = 1;
}
if(this.countPlayerUnits(this.MAP.TERRITORIES_ARR,_loc10_) > 0)
{
_global.setTimeout(mx.utils.Delegate.create(this,this.nextPlayer),2000);
_loc13_ = true;
}
else
{
this.PLAYER_MOVE = this.PLAYER_MOVE + 1;
}
}
}
function unitsToAdd(player)
{
var _loc6_ = new Array();
var _loc2_ = 0;
while(_loc2_ < this.MAP.TERRITORIES_ARR.length)
{
if(this.MAP.TERRITORIES_ARR[_loc2_].player == player)
{
_loc6_.push(this.MAP.TERRITORIES_ARR[_loc2_]);
}
_loc2_ = _loc2_ + 1;
}
var _loc3_ = new Array();
_loc2_ = 0;
while(_loc2_ < _loc6_.length)
{
var _loc5_ = _loc6_[_loc2_];
if(this.isThere(_loc5_,_loc3_) == false)
{
var _loc4_ = new Array();
this.generate(_loc5_,_loc4_);
_loc3_.push(_loc4_);
}
_loc2_ = _loc2_ + 1;
}
var _loc7_ = 0;
_loc2_ = 0;
while(_loc2_ < _loc3_.length)
{
if(_loc3_[_loc2_].length > _loc7_)
{
_loc7_ = _loc3_[_loc2_].length;
}
_loc2_ = _loc2_ + 1;
}
return _loc7_;
}
function generate(terr, arrToFill)
{
if(this.isThere2(terr,arrToFill) == false)
{
arrToFill.push(terr);
var _loc3_ = this.neighboursAreasArr(terr.arr);
var _loc2_ = 0;
while(_loc2_ < _loc3_.length)
{
this.generate(_loc3_[_loc2_],arrToFill);
_loc2_ = _loc2_ + 1;
}
}
}
function isThere2(terr, arr)
{
var _loc1_ = 0;
while(_loc1_ < arr.length)
{
if(arr[_loc1_] == terr)
{
return true;
}
_loc1_ = _loc1_ + 1;
}
return false;
}
function isThere(terr, arr)
{
var _loc2_ = 0;
while(_loc2_ < arr.length)
{
var _loc1_ = 0;
while(_loc1_ < arr[_loc2_].length)
{
if(arr[_loc2_][_loc1_] == terr)
{
return true;
}
_loc1_ = _loc1_ + 1;
}
_loc2_ = _loc2_ + 1;
}
return false;
}
function neighboursAreasArr(terrArr)
{
var _loc6_ = new Array();
var _loc7_ = 0;
while(_loc7_ < terrArr.length)
{
var _loc4_ = terrArr[_loc7_];
var _loc3_ = [_loc4_.TL,_loc4_.L,_loc4_.TR,_loc4_.BR,_loc4_.R,_loc4_.BL];
var _loc1_ = 0;
while(_loc1_ < _loc3_.length)
{
if(_loc3_[_loc1_]._territory != _loc4_._territory && _loc3_[_loc1_]._territory.player == _loc4_._territory.player)
{
var _loc5_ = false;
var _loc2_ = 0;
while(_loc2_ < _loc6_.length && !_loc5_)
{
if(_loc6_[_loc2_] == _loc3_[_loc1_]._territory)
{
_loc5_ = true;
}
_loc2_ = _loc2_ + 1;
}
if(!_loc5_)
{
_loc6_.push(_loc3_[_loc1_]._territory);
}
}
_loc1_ = _loc1_ + 1;
}
_loc7_ = _loc7_ + 1;
}
return _loc6_;
}
function fightFinished()
{
this.MAP.winnerFound();
if(this.PLAYER_MOVE == 1)
{
this.MAP.selectA();
}
else
{
var root = this;
this.TRACER.ct = 0;
this.TRACER.onEnterFrame = function()
{
this.ct = this.ct + 1;
if(this.ct > 15)
{
root.nextAImove();
delete this.onEnterFrame;
}
};
}
this.FIGHTBOX.resetWinner();
}
function nextAImove(oldID)
{
this.AI.cleverMove();
}
function kill()
{
delete this.TRACER.onEnterFrame;
}
function clearAll()
{
var _loc2_ = 0;
while(_loc2_ < this.rubbish_arr.length)
{
this.rubbish_arr[_loc2_].removeMovieClip();
_loc2_ = _loc2_ + 1;
}
}
function random2(z)
{
return Math.round(Math.random() * z);
}
function random3(z)
{
var _loc4_ = new Array();
var _loc3_ = 0;
while(_loc3_ <= z)
{
var _loc2_ = 0;
while(_loc2_ <= _loc3_)
{
_loc4_.push(_loc3_);
_loc2_ = _loc2_ + 1;
}
_loc3_ = _loc3_ + 1;
}
return _loc4_[this.random2(_loc4_.length - 1)];
}
function shuffledArray(arr)
{
var _loc5_ = 0;
while(_loc5_ < 20)
{
var _loc4_ = this.random2(arr.length - 1);
var _loc3_ = this.random2(arr.length - 1);
var _loc6_ = arr[_loc4_];
arr[_loc4_] = arr[_loc3_];
arr[_loc3_] = _loc6_;
_loc5_ = _loc5_ + 1;
}
return arr;
}
function countPlayerUnits(terrArr, pl)
{
var _loc3_ = 0;
var _loc1_ = 0;
while(_loc1_ < terrArr.length)
{
if(terrArr[_loc1_].player == pl)
{
_loc3_ += terrArr[_loc1_].unitsNO;
}
_loc1_ = _loc1_ + 1;
}
return _loc3_;
}
}